<?php
class LESSPHP_Plugin_Mixins extends LESSPHP_Plugin_Abstract{
	
	public function apply(SimpleXMLElement $cssXml){
		$results = $cssXml->xpath('//mixin/..');
		foreach ($results as $result){
			foreach($result->mixin as $mixin){
				$mixin = (string)$mixin;
				
				
				$mixResults = $cssXml->xpath('/css/ruleset[contains(selector,\'' . $mixin . '\')]');
				if(empty($mixResults)) continue;
				foreach($mixResults as $mixResult){
					
					if(count($mixResult->selector) !== 1) continue;
					foreach($mixResult->property as $property){
						$node = $result->addChild('property', (string)$property);
						$node->addAttribute('type', $property['type']);
					}
				}
			}
			
		}
		//die;
	}
	public function transformCss($css){
		return preg_replace('/([\\s{])(\\.[a-zA-Z0-9_-]+)\\s?;/', '$1<mixin>$2</mixin>', $css);
	}
	
}